﻿using AutoduelClient.GameClient.Network;
/* Autoduel Game
 * CS4911 Senior Design Project
 * Fall 2010 Semester
 * Ian Axelrod, Liz Ha, Andrew Muldowney, Edward Futch
 */
using AutoduelClient.GameUI;

namespace AutoduelClient
{
    /// <summary>
    /// This class listens for messages sent from the server to the
    /// grid this player inhabits
    /// </summary>
    public class GridChannelListener : ClientChannelListener
    {
		#region Fields (1)
		// reference to an instance of the game
        private Game game;
		#endregion

		#region Constructors (1)
		/// <summary>
        /// Create an instance of the GridchannelListener
        /// </summary>
        /// <param name="game">Reference to an instance of the game</param>
        public GridChannelListener(Game game) {
            this.game = game;
        }
		#endregion

		#region Methods (2)

		/// <summary>
        /// Called when we have left the channel
        /// </summary>
        /// <param name="channel">The channel we have left</param>
        public void LeftChannel(ClientChannel channel)
        {
            System.Diagnostics.Debug.WriteLine("[Grid] Client left channel " + channel);
        }

		/// <summary>
        /// Received a message from the server's channel
        /// </summary>
        /// <param name="channel">The channel that sent the message</param>
        /// <param name="message">The message that was sent</param>
        public void ReceivedMessage(ClientChannel channel, byte[] message)
        {
            System.Diagnostics.Debug.WriteLine("[Grid] Received message from channel " + channel);
            this.game.Messages.Enqueue(new Packet(MSGORGNS.GRID, message));
        }

		#endregion
    }
}
